package org.gw.building.repositories.dkgg;

import org.gw.building.model.Kqy;
import org.gw.ylc.base.model.Administrator;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface KqyRepository extends JpaRepository<Kqy, String>{
	@Query("select count(1) from Kqy t where t.kqyh = ?1")
	Long findCountByKqy(String kqyh);

	@Query("from Kqy t where (?1 is null or t.kqyh = ?1) and (?2 is null or t.kqy like ?2) order by t.kqyh desc")
	Page<Kqy> queryPage(String id, String xm, Pageable pageable);

	@Query( value = "SELECT a.id,  a.id kqyid, a.employeeNo kqyh, a.name kqy FROM administrator a WHERE a.status=1 and a.employeeNo not in (SELECT k.kqyh from t_qmgc_kqy k) and " +
			"(?1 is null or a.employeeNo like ?1 or a.name like ?1) /*#pageable*/",
			countQuery = "SELECT count(1) FROM administrator a WHERE a.status=1 and a.employeeNo not in (SELECT k.kqyh from t_qmgc_kqy k) and " +
					"(?1 is null or a.employeeNo like ?1 or a.name like ?1)",
			nativeQuery = true)
	Page<Kqy> queryUserPage(String kqy, Pageable psageable);
}
